package com.zhouxiaoge.jenkins.web;

import com.zhouxiaoge.jenkins.core.service.JenkinsManageWorkFlowService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 周明阳
 * @date 2019/7/18 16:01
 */

@Api(tags = "jenkins操作WorkFlow接口对接")
@RestController
@RequestMapping(value = "/jenkins/workFlow")
@Slf4j
public class JenkinsWorkFlowController {

    private final JenkinsManageWorkFlowService jenkinsManageWorkFlowService;

    public JenkinsWorkFlowController(JenkinsManageWorkFlowService jenkinsManageWorkFlowService) {
        this.jenkinsManageWorkFlowService = jenkinsManageWorkFlowService;
    }

    //创建Jenkins流水线job
    @PostMapping("/createWorkFlow")
    public String createWorkFlow(String workFlowName) {
        jenkinsManageWorkFlowService.createWorkFlow(workFlowName);
        return "SUCCESS";
    }

    //修改Jenkins流水线job
    @PostMapping("/updateWorkFlow")
    public String updateWorkFlow(String workFlowName, String pipelineXml) {
        jenkinsManageWorkFlowService.updateWorkFlow(workFlowName, pipelineXml);
        return "SUCCESS";
    }

    // 流水线构建状态
    // http://47.105.218.225:3020/jenkins/job/pipelineTest/wfapi/runs?fullStages=true&_=1563758642628
    @GetMapping
    public String acquireWorkFlowStatus(String workFlowName) {

        return "SUCCESS";
    }

}
